<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class OrderResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'payment' => $this->payment,
            'postage' => $this->postage,
            'status' => $this->status,
            'trade_no' => $this->trade_no,
            'pay_time' => $this->pay_time,
            'tracking_type' => $this->tracking_type,
            'tracking_number' => $this->tracking_number,
            'products' => ProductResource::collection($this->products),
            'address' => $this->address,
            'created_at' => $this->created_at->toDateTimeString(),
            'updated_at' => $this->updated_at->toDateTimeString(),
        ];
    }
}
